package com.me.jingdongshop.model.protocol;

import com.me.common.base.Const;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created on 2017/5/4.
 * @author Chilam
 *
 * Retrofit单例
 */

public class RetrofitManager {
    private Retrofit mRetrofit;
    private IHttpService mHttpService;

    private void initRetrofit(){
        OkHttpClient.Builder client = new OkHttpClient.Builder();

        mRetrofit = new Retrofit.Builder()
                .baseUrl(IHttpService.HOST_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(client.build())
                .build();
        mHttpService = mRetrofit.create(IHttpService.class);
    }
    public Retrofit getRetrofit(){
        return mRetrofit;
    }

    public IHttpService getHttpService(){
        return mHttpService;
    }

    private RetrofitManager(){
        initRetrofit();
    }

    private static class SingleHolder{
        public static RetrofitManager instance = new RetrofitManager();
    }

    public static RetrofitManager getInstance(){
        return SingleHolder.instance;
    }
}
